package cn;

import java.util.Arrays;
import java.util.Scanner;

public class BubbleSort {
	

	int[] input() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入长度：");
		int len = sc.nextInt();
		int[] oldArr = new int[len];
		System.out.println("请输入数组中的元素：");
		for (int i = 0; i < len; i++) {
			oldArr[i] = sc.nextInt();
		}
		return oldArr;
	}

	int[] maoSort(int[] newArr) {
		for (int i = 0; i < newArr.length - 1; i++) {
			for (int j = 0; j <newArr.length - 1 - i; j++) {
				if (newArr[j] <newArr[j + 1]) {
					int temp = newArr[j + 1];
					newArr[j + 1] =newArr[j];
					newArr[j] = temp;
				}
			}
		}
		return newArr;
	}

	void outPut(int[] newArr) {
		System.out.println(Arrays.toString(newArr));
		System.out.println();
	}

	public static void main(String[] args) {
		BubbleSort b = new BubbleSort();
		int[] arr = b.input();
		b.outPut(arr);
		int[] newArr = b.maoSort(arr);
		b.outPut(newArr);

	}
}
